package com.yuwubao.uav.tool.service.impl;

import com.yuwubao.framework.bean.PageData;
import com.yuwubao.uav.tool.mapper.EvaluationMapper;
import com.yuwubao.uav.tool.service.EvaluationService;
import com.yuwubao.uav.tool.util.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class EvaluationServiceImpl implements EvaluationService {

    private static final Logger logger = LogManager.getLogger(EvaluationServiceImpl.class.getName());

    @Resource
    private EvaluationMapper evaluationMapper;

    @Override
    public void clickEvaluation(PageData pageData) throws Exception {
        try{
            evaluationMapper.clickEvaluation(pageData);

        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void deleteEvaluation(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    evaluationMapper.deleteEvaluation(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateEvaluation(PageData pageData) throws Exception {
        try{
            evaluationMapper.updateEvaluation(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableEvaluation(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    evaluationMapper.disableOrEnableEvaluation(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableEvaluationType(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    evaluationMapper.disableOrEnableEvaluationType(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addEvaluation(PageData pageData) throws Exception {
        try{
            evaluationMapper.addEvaluation(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listEvaluation(PageData pageData) throws Exception {
        try{
            return evaluationMapper.listEvaluation(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listEvaluationCount(PageData pageData) throws Exception {
        try{
            return evaluationMapper.listEvaluationCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

    @Override
    public void deleteEvaluationType(PageData pageData) throws Exception {
        try{

            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");

            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    evaluationMapper.deleteEvaluationType(pageData);

                }
            }


        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateEvaluationType(PageData pageData) throws Exception {
        try{
            evaluationMapper.updateEvaluationType(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public void addEvaluationType(PageData pageData) throws Exception {
        try{
            String names = pageData.get("names") == null ? "" : pageData.getString("names");
            if (StringUtil.isNotNvlOrBlank(names)) {
                String[] nameArr = names.split(",");
                if (nameArr != null && nameArr.length>0) {
                    for (String name : nameArr) {
                        pageData.put("name",name);
                        evaluationMapper.addEvaluationType(pageData);
                    }
                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listEvaluationType(PageData pageData) throws Exception {
        try{
            return evaluationMapper.listEvaluationType(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public List<PageData> listEvaluationTypeAll(PageData pageData) throws Exception {
        try{
            return evaluationMapper.listEvaluationTypeAll(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listEvaluationTypeCount(PageData pageData) throws Exception {
        try{
            return evaluationMapper.listEvaluationTypeCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

}
